﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using SIPO.Library.DomainObject.Administration;
using SIPO.Library.DataAccess.Administration;
using SIPO.Library.DomainObject.Transaction;
using SIPO.Library.DataAccess.Transaction;
using System.Configuration;
using SIPO.Library.DataAccess.Administration.Catalog;
using SIPO.Library.DomainObject.Administration.Catalog;

namespace SIPO.Web.Forms.Transaction
{
    public partial class recImpositionform : BasePage
    {
        private int id = -1;

        protected override void OnLoad(EventArgs e)
        {
            if (Request.Params["id"] != null)
            {
                id = Convert.ToInt32(Request.Params["id"]);
            }

            if (!Page.IsPostBack)
            {
                this.BindYear();
                //populate dropdownlist debtor
                recDebtorRepo recDebtorRepo = new recDebtorRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
                List<recDebtor> debtors = recDebtorRepo.GetList(base.SubSubSectorIDs);
                ddlDebtor.Items.Clear();
                debtors.ForEach(delegate(recDebtor debtor)
                {
                    ddlDebtor.Items.Add(new ListItem(debtor.DebtorCode + " - " + debtor.DebtorName, debtor.DebtorID.ToString()));
                });
                ddlDebtor.Items.Insert(0, new ListItem("-- pilih debitur --", string.Empty));

                //populate dropdownlist dasar pengenaan
                recImpositionBaseRepo recImpositionBaseDal = new recImpositionBaseRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
                List<recImpositionBase> impositionBases = recImpositionBaseDal.GetList();
                ddlImpositionBase.Items.Clear();
                impositionBases.ForEach(delegate(recImpositionBase impositionBase)
                {
                    ddlImpositionBase.Items.Add(new ListItem(impositionBase.ImpositonBaseName, impositionBase.ImpositionBaseID.ToString()));
                });
                ddlImpositionBase.Items.Insert(0, new ListItem("-- pilih dasar pengenaan --", string.Empty));

                //
                ddlSubSubSector.Items.Insert(0, new ListItem("-- pilih sub sub sektor --", string.Empty));

                if (id > 0) // Edit an existing item
                {
                    //trInvoice.Visible = true;
                    //trInvoiceDate.Visible = true;
                    //trPayment.Visible = true;
                    //trPaymentDate.Visible = true;

                    //recImpositionRepo recImpositionDal = new recImpositionRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
                    //recImposition recImposition = recImpositionDal.GetById(id);
                    //if (recImposition != null)
                    //{

                    //    recDebtorSectorRepo recDebtorSectorRepo = new recDebtorSectorRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
                    //    List<recDebtorSector> sectordebtors = recDebtorSectorRepo.GetList();

                    //    ddlDebtorSector.Items.Clear();
                    //    sectordebtors.ForEach(delegate(recDebtorSector sectordebtor)
                    //    {
                    //        recSubSubSectorRepo recSubSubSectorRepo = new recSubSubSectorRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
                    //        recSubSubSector recSubSubSector = recSubSubSectorRepo.GetById(sectordebtor.SubSubSectorID);
                    //        ddlDebtorSector.Items.Add(new ListItem(recSubSubSector.SubSubSectorCode + " - " + recSubSubSector.SubSubSectorName, sectordebtor.DebtorSectorID.ToString()));
                    //    });

                    //    ddlDebtorSector.Items.Insert(0, new ListItem("-- pilih sub sub sektor --", string.Empty));

                    //    hfID.Value = id.ToString();
                    //    ddlDebtorSector.Items.FindByValue(recImposition.DebtorSectorID.ToString()).Selected = true;
                    //    ddlSanctionType.Items.FindByValue(recImposition.SanctionTypeID.ToString()).Selected = true;
                    //    txtLetterNo.Text = recImposition.LetterNo;
                    //    txtLetterDate.Text = recImposition.LetterDate.Value.ToString("dd/MM/yyyy");
                    //    txtValue.Text = recImposition.Value.ToString("#");
                    //    txtInvoiceNo.Text = recImposition.InvoiceNo;
                    //    if (recImposition.InvoiceDate!=null && recImposition.InvoiceDate.Value.ToString() != "")
                    //        txtInvoiceDate.Text = recImposition.InvoiceDate.Value.ToString("dd/MM/yyyy");
                    //    txtLetterNo.Text = recImposition.LetterNo;
                    //    if (recImposition.LetterDate!=null && recImposition.LetterDate.Value.ToString() != "")
                    //        txtLetterDate.Text = recImposition.LetterDate.Value.ToString("dd/MM/yyyy");

                    //    recDebtorSector recDebtorSector = recDebtorSectorRepo.GetById(recImposition.DebtorSectorID);
                    //    if (recDebtorSector != null)
                    //        ddlDebtor.Items.FindByValue(recDebtorSector.DebtorID.ToString()).Selected = true;




                    //    hfInvoiceNo.Value = recImposition.InvoiceNo.Trim();



                    // }
                }
            }

        }

        private void BindYear()
        {
            int currentTahunLapKeuYear = DateTime.Now.Year - 3;
            int nextYear = DateTime.Now.Year + 10;

            IList<int> collTahunLapKeuYears = new List<int>();

            for (int i = currentTahunLapKeuYear; i < nextYear; i++)
            {
                collTahunLapKeuYears.Add(i);
            }

            ddlTahunLapKeu.DataSource = collTahunLapKeuYears;
            ddlTahunLapKeu.DataBind();
        }

    }
}
